<template>
  <div class="goodsAnalysis">
    <div class="vip_pay_box" v-if="showPageVip">
      <div class="vip_bg_box">
        <div class="vip_bg_mask"></div>
      </div>
      <div class="vip_box_wrap">
        <payVip routerName="FansPortrait" :lowestVipNum="4" />
      </div>
    </div>
    <template v-else>
      <div class="top">
        <radio_group01
          :radio_values="['近7天', '30天', '90天']"
          v-model="KindName"
          class="tab01"
        />
        <div class="optionsBox">
          <el-date-picker
            class="long_time"
            v-model="liveTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            prefix-icon="el-icon-arrow-down"
            unlink-panels
            :clearable="false"
            :picker-options="pickeroptions"
            value-format="yyyy-MM-dd"
            @change="onPick1"
          ></el-date-picker>
        </div>
      </div>
      <p class="title">商品概览</p>
      <ul class="generalization">
        <li>
          <p>{{ format_num(summary.goods_count) }}</p>
          <p>商品数</p>
        </li>
        <li>
          <p>{{ format_num(summary.goods_volume) }}</p>
          <p>总预估销量</p>
        </li>
        <li>
          <p>{{ format_num(summary.goods_amount) }}</p>
          <p>总预估销售额</p>
        </li>
      </ul>
      <p class="title">商品销售量趋势</p>
      <div class="chart">
        <goodschart
          name1="销量"
          v-if="chart_x"
          :xData="chart_x"
          :series1="chart_y"
          :proVolume="proVolume"
        />
      </div>
      <p class="title">商品信息</p>
      <div :class="salepro.length ? '' : 'pontion'">
        <ul class="goods_list">
          <li>商品</li>
          <li>售价</li>
          <li>销量</li>
          <li>销售额</li>
          <li>操作</li>
        </ul>
        <ul class="goods_list_data" v-if="salepro.length">
          <li v-for="(item, i) in salepro" :key="i + 'a'">
            <div class="img_tit">
              <img
                :src="item.proLogo"
                v-if="item.proLogo"
                alt
                @click="toGoodsDetails(item.proId, '0')"
                v-errorImg:shop
              />
              <img
                :src="defaultSrc"
                v-else
                alt
                @click="toGoodsDetails(item.proId, '0')"
              />
              <div class="rightBox">
                <div class="goods_iden" v-if="item.proSign != 0">
                  {{
                    item.proSign == 1
                      ? "自有"
                      : item.proSign == 2
                      ? "广场"
                      : item.proSign == 3
                      ? "自有&广场"
                      : ""
                  }}
                </div>
                <p @click="toGoodsDetails(item.proId, '0')">
                  {{ item.proTitle }}
                </p>
              </div>
            </div>
            <div class="price">￥{{ item.proPrice }}</div>
            <div class="sales_volume">{{ format_num(item.volume) }}</div>
            <div class="sales_volume">{{ format_num(item.amount) }}</div>
            <div class="operation">
              <button @click="videoPop(item.proId)">关联视频</button>
            </div>
          </li>
        </ul>
        <div
          v-loading="loading"
          v-if="loading"
          class="loading"
          element-loading-text="拼命加载中..."
          element-loading-spinner="el-icon-loading"
        ></div>
        <div v-if="!salepro.length && !loading" class="zw">
          <img src="@/assets/liu/zw.png" />
          <p>暂无数据</p>
        </div>
      </div>
      <div v-if="salepro.length" class="Popupline">我是有底线的~</div>
      <el-dialog
        @close="close"
        :visible.sync="popupList"
        custom-class="buyDialog"
      >
        <div class="pop_box">
          <p class="title">关联视频</p>
          <div class="ul_box">
            <ul class="ul_01">
              <li>视频</li>
              <li>达人</li>
              <li>点赞数</li>
              <li>评论数</li>
              <li>转发数</li>
            </ul>
            <ul class="ul_02">
              <li v-for="(item, i) in awemePop" :key="i + 'ii'">
                <div>
                  <img :src="item.thumpic" @click="goVideo(item.awemeid)" alt />
                  <p @click="goVideo(item.awemeid)">{{ item.title }}</p>
                </div>
                <div>
                  <img :src="item.logo" alt />
                  <div>
                    <p @click="go_to_page01(item.authorid)">
                      {{ item.nickname }}
                    </p>
                    <p @click="go_to_page01(item.authorid)">
                      抖音号：{{ item.unique_id }}
                    </p>
                  </div>
                </div>
                <div>{{ format_num(item.total_favorite) }}</div>
                <div>{{ format_num(item.total_comment) }}</div>
                <div>{{ format_num(item.total_share) }}</div>
              </li>
            </ul>
            <div
              v-loading="loading_01"
              v-if="loading_01"
              class="loading"
              element-loading-text="拼命加载中..."
              element-loading-spinner="el-icon-loading"
            ></div>
          </div>

          <div
            v-if="
              (!awemePop && !loading_01) || (!awemePop.length && !loading_01)
            "
            class="zw"
          >
            <img src="@/assets/liu/zw.png" />
            <p>暂无数据</p>
          </div>

          <div class="pageBox">
            <el-pagination
              background
              layout="prev, pager, next, jumper"
              :total="count"
              :page-size="size"
              :current-page="page"
              @current-change="get_data"
              :hide-on-single-page="true"
            ></el-pagination>
          </div>
        </div>
      </el-dialog>
    </template>
  </div>
</template>

<script>
import goodschart from "./KChartGoods.vue";
import defaultSrc from "@/assets/img/shop.png";
export default {
  props: {},
  data() {
    return {
      defaultSrc: defaultSrc, //默认图片
      proid: null,
      loading_01: false,
      loading: true,
      popupList: false, //弹窗
      summary: [],
      salepro: [],
      awemePop: [], //视频弹窗
      size: 5,
      page: 1,
      count: null,
      startDate: "",
      proVolume: [],
      chart_x: null,
      chart_y: null,
      endDate: "",
      KindName: "30天",
      showPageVip: false,
      liveTime: [], // 选择时间 不可选的日期.
      pickeroptions: {
        disabledDate: (time) => {
          return (
            time.getTime() < Date.now() - 90 * 24 * 60 * 60 * 1000 ||
            time.getTime() > Date.now()
          ); // 返回 所有时间 大于 当前时间
        },
      },
    };
  },
  components: { goodschart },

  computed: {},
  watch: {
    KindName: function (newVal, oldVal) {
      this.summary = [];
      this.salepro = [];
      if (this.KindName != "") {
        this.KindName = newVal;
        this.getSalepro();
        this.sale();
      }
    },
  },
  created() {
    this.sale();
    this.getSalepro();
  },
  mounted() {},

  methods: {
    goVideo(id) {
      let router = this.$router.resolve({
        path: "/talent_main/videoDetails",
        query: { id },
      });
      window.open(router.href, "_blank");
    },
    videoPop(id) {
      this.proid = id;
      this.page = 1;
      this.popupList = true;
      this.searchSimilarAweme();
    },
    close() {},
    //   分页
    get_data(page) {
      this.awemePop = [];

      this.page = page;
      this.searchSimilarAweme();
    },
    searchSimilarAweme() {
      this.loading_01 = true;
      this.$axios
        .get(
          `/api/aweme/searchSimilarAweme?proid=${this.proid}&api-version=2&stime=${this.startDate}&etime=${this.endDate}&page=${this.page}&size=${this.size}`
        )
        .then((res) => {
          this.loading_01 = false;
          if (res.data.code == 0) {
            this.awemePop = res.data.data;
            this.count = res.data.count;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //达人详情
    go_to_page01(id) {
      let router = this.$router.resolve({
        path: `/talent_main/tdetails/${id}/${0}`,
      });
      window.open(router.href, "_blank");
    },
    // 跳商品详情
    toGoodsDetails(id, tabNo) {
      let router = this.$router.resolve({
        path: `/talent_main/shop_main/${id}/${tabNo}`,
      });
      window.open(router.href, "_blank");
    },
    // 获取视频商品列表V2
    getSalepro() {
      this.loading = true;
      this.getTime();
      this.$axios
        .get(
          `/api/aweme/salepro?awemeid=${this.$route.query.id}&api-version=2&stime=${this.startDate}&etime=${this.endDate}`
        )
        .then((result) => {
          if (result.data.code == 0) {
            this.salepro = result.data.data;
            this.loading = false;
          } else {
            this.loading = false;
          }
          if (result.data.code == 1003) {
            this.showPageVip = true;
          }
        })
        .catch((err) => {});
    },
    // 获取视频销量V2
    sale() {
      this.getTime();
      this.$axios
        .get(
          `api/aweme/sale?awemeid=${this.$route.query.id}&api-version=2&stime=${this.startDate}&etime=${this.endDate}`
        )
        .then((result) => {
          if (result.data.code == 0) {
            this.summary = result.data.data.summary;
            this.chart_x = result.data.data.chart.ctime.map((item) => {
              return this.timestamp(item, "M-D");
            });
            this.chart_y = result.data.data.chart.volume;
            this.proVolume = result.data.data.chart.proVolume;
          }
          if (result.data.code == 1003) {
            this.showPageVip = true;
          }
        })
        .catch((err) => {});
    },
    // 时间
    getTime() {
      switch (this.KindName) {
        case "近7天":
          this.endDate = this.timestamp(Date.now() / 1000, "Y-M-D");
          this.startDate = this.timestamp(
            Date.now() / 1000 - 86400 * 6,
            "Y-M-D"
          );
          break;

        case "30天":
          this.endDate = this.timestamp(Date.now() / 1000, "Y-M-D");
          this.startDate = this.timestamp(
            Date.now() / 1000 - 86400 * 29,
            "Y-M-D"
          );
          break;
        case "90天":
          this.endDate = this.timestamp(Date.now() / 1000, "Y-M-D");
          this.startDate = this.timestamp(
            Date.now() / 1000 - 86400 * 89,
            "Y-M-D"
          );
          break;
        default:
          this.startDate = this.liveTime[0];
          this.endDate = this.liveTime[1];
          break;
      }
      this.liveTime = [this.startDate, this.endDate];
    },
    onPick1() {
      this.KindName = "";
      this.summary = [];
      this.salepro = [];
      this.getSalepro();
      this.sale();
    },
  },
};
</script>

<style lang="less" scoped>
.goodsAnalysis {
  .pontion {
    position: relative;
    height: 300px;
  }
  .zw {
    top: 180px;
  }
  padding-left: 20px;
  padding-right: 20px;
  width: 100%;
  box-sizing: border-box;
  .top {
    margin-bottom: 20px;
    // width: 100%;
    display: flex;
    justify-content: flex-end;
    .optionsBox {
      margin-left: 10px;
    }
  }
  .title {
    font-size: 16px;
    font-weight: 600;
    color: #222222;
    position: relative;
    text-indent: 10px;
    margin-bottom: 20px;
    &::after {
      content: "";
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      width: 4px;
      height: 16px;
      background-color: #fd7f2c;
      border-radius: 2px;
    }
  }
  .generalization {
    display: flex;
    height: 120px;
    justify-content: center;
    > li {
      align-self: center;
      position: relative;
      width: 306px;
      &:nth-child(1),
      &:nth-child(2) {
        &::after {
          content: "";
          position: absolute;
          right: 0;
          top: 0;
          width: 1px;
          height: 45px;
          background-color: #efefef;
        }
      }

      p {
        text-align: center;
        &:nth-child(1) {
          font-family: DINAlternate-Bold;
          font-size: 24px;
          color: #222222;
        }
        &:nth-child(2) {
          font-size: 12px;
          color: #888888;
        }
      }
    }
  }
  .chart {
    // margin-top: 30px;
    margin-bottom: 35px;
    width: 100%;
    height: 239px;
  }
  .goods_list {
    width: 100%;
    height: 48px;
    background-color: #f5f9ff;
    border-radius: 4px 4px 0px 0px;
    display: flex;
    li {
      align-self: center;
      font-size: 14px;
      font-weight: 600;
      color: #555555;
      &:nth-child(1) {
        width: 40%;
        padding-left: 45px;
        box-sizing: border-box;
      }
      &:nth-child(2),
      &:nth-child(3),
      &:nth-child(4),
      &:nth-child(5) {
        text-align: center;
        width: 15%;
      }
    }
  }
  .goods_list_data {
    width: 100%;
    li {
      display: flex;
      height: 79px;
      border-bottom: 1px solid #efefef;
      .img_tit {
        width: 40%;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        cursor: pointer;
        padding-left: 24px;
        box-sizing: border-box;
        img {
          width: 50px;
          height: 50px;
          border-radius: 6px;
          border: 1px solid #e5e5e5;
        }
        .rightBox {
          flex: 0 0 calc(100% - 70px);
          font-size: 14px;
          font-weight: 600;
          color: #222222;
          position: relative;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
          margin-left: 10px;
          text-align: left;
          p {
            cursor: pointer;
            display: inline;
            &:hover {
              color: #ff924b;
            }
          }
          .goods_iden {
            text-align: center;
            display: inline-block;
            // width: 32px;
            height: 16px;
            background-color: #fff7ee;
            border-radius: 4px;
            border: solid 1px #fd7f2c;
            font-size: 12px;
            font-weight: normal;
            line-height: 16px;
            color: #fd7f2c;
          }
        }
        // display: flex;
        // width: 40%;
        // padding-right: 45px;
        // > img {
        //   align-self: center;
        //   width: 50px;
        //   height: 50px;
        //   border-radius: 6px;
        //   margin-left: 35px;
        //   margin-right: 8px;
        //   cursor: pointer;
        // }
        // > p {
        //   width: 70%;
        //   align-self: center;
        //   font-size: 14px;
        //   font-weight: 600;
        //   color: #222222;
        //   display: -webkit-box;
        //   -webkit-box-orient: vertical;
        //   -webkit-line-clamp: 2;
        //   overflow: hidden;
        //   &:hover {
        //     color: #ff924b;
        //     cursor: pointer;
        //   }
        // }
        .goods_iden {
          text-align: center;
          display: inline-block;
          // width: 32px;
          height: 16px;
          background-color: #fff7ee;
          border-radius: 4px;
          border: solid 1px #fd7f2c;
          font-size: 12px;
          font-weight: normal;
          line-height: 16px;
          color: #fd7f2c;
          padding: 0 4px;
        }
      }
      .price,
      .sales_volume,
      .operation {
        align-self: center;
        text-align: center;
        width: 15%;
      }
      .operation {
        > button {
          width: 88px;
          height: 32px;
          border: 1px solid #fd7f2c;
          border-radius: 4px;
          font-size: 14px;
          color: #fd7f2c;
          &:hover {
            border: 1px solid #ff924b;
            color: #ff924b;
          }
        }
      }
    }
  }
  .pop_box {
    padding: 20px;
    .ul_01 {
      width: 1060px;
      height: 48px;
      background-color: #f4f9ff;
      border-radius: 4px 4px 0px 0px;
      display: flex;
      > li {
        font-size: 14px;
        font-weight: 600;
        color: #555555;
        align-self: center;
        &:nth-child(1) {
          width: 35%;
          margin-left: 36px;
        }
        &:nth-child(2) {
          width: 25%;
        }
        &:nth-child(3),
        &:nth-child(4),
        &:nth-child(5) {
          width: 15%;

          text-align: center;
        }
      }
    }
  }
  .ul_02 {
    // height: 400px;
    > li {
      display: flex;
      height: 79px;
      border-bottom: 1px solid #efefef;
      > div {
        align-self: center;
        &:nth-child(1) {
          width: 35%;
          margin-left: 25px;
          display: flex;
          box-sizing: border-box;
          padding-right: 3%;

          > img {
            width: 50px;
            height: 50px;
            background-color: #ff7600;
            border-radius: 6px;
            margin-right: 8px;
            cursor: pointer;
          }
          > p {
            width: 230px;
            font-size: 14px;
            font-weight: 600;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
            height: 40px;
            color: #222222;
            align-self: center;
            &:hover {
              color: #ff924b;
              cursor: pointer;
            }
          }
        }
        &:nth-child(2) {
          display: flex;
          width: 25%;

          > img {
            cursor: pointer;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            margin-right: 5px;
          }
          > div {
            align-self: center;
            > p {
              &:nth-child(1) {
                font-size: 14px;
                font-weight: 600;
                color: #222222;
                width: 109px;
                margin-bottom: 2px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
                &:hover {
                  color: #ff924b;
                  cursor: pointer;
                }
              }
              &:nth-child(2) {
                font-size: 13px;
                color: #888888;
              }
            }
          }
        }
        &:nth-child(3),
        &:nth-child(4),
        &:nth-child(5) {
          width: 15%;
          font-family: DINAlternate-Bold;
          color: #222222;
          text-align: center;
          align-self: center;
        }
      }
    }
  }
  // 弹窗底线~
  .Popupline {
    font-size: 14px;
    color: #888;
    text-align: center;
    // height: 40px;
    // line-height: 40px;
    padding-top: 30px;
  }
  .zw {
    margin-top: 100px;
    z-index: 100;
  }
  .ul_box {
    height: 448px;
    overflow: hidden;
  }
}
</style>
